create database temp_Forum_marketing
on
use temp_Forum_marketing
on

--drop TABLE FORUM 
CREATE TABLE FORUM 
(
forumID int identity(1,1),
forumname nvarchar(50),
ForumType nvarchar(50),
LinkForum nvarchar(200),
LinkHome nvarchar(200),
LinkLogin nvarchar(200),
EncodingType nvarchar(50),
_Description nvarchar(50),
IsActived bit,
IsDeleted bit,

primary key(forumID)
)

select * from FORUM 
create proc usp_CapNhat
@forumname nvarchar(50),
@ForumType nvarchar(50),
@LinkForum nvarchar(200),
@LinkHome nvarchar(200),
@LinkLogin nvarchar(200),
@EncodingType nvarchar(50),
@_Description nvarchar(50),
@IsActived bit,
@IsDeleted bit
as
begin
insert into FORUM(forumname,
ForumType,
LinkForum,
LinkHome,
LinkLogin,
EncodingType,
_Description,
IsActived,
IsDeleted) 
values(@forumname ,@ForumType ,@LinkForum ,@LinkHome ,@LinkLogin ,@EncodingType ,@_Description ,@IsActived ,@IsDeleted )
end

--exec usp_CapNhat 
--@forumname ='UN',
--@ForumType ='UN',
--@LinkForum ='none',
--@LinkHome ='none',
--@LinkLogin ='none',
--@EncodingType ='none',
--@_Description ='none',
--@IsActived=1,
--@IsDeleted=1
go
if OBJECT_ID ('temp') is not null
drop table temp
go
create table temp
(
ID int,
Name nvarchar(100),
isDelete bit,
primary key(ID)
)
go
if OBJECT_ID('usp_InsertTableTemp') is not null
drop proc usp_InsertTableTemp
go
create procedure usp_InsertTableTemp
@Table Table(
ID int identity(1,1),
Name nvarchar(100),
isDelete bit)
as
begin
	insert into temp ()
end


select * from temp 

create table chau
(
id int ,
name nvarchar(100),
isdelete bit
)

insert into chau values(1,N'chau',1)
insert into chau values(2,N'chi',0)

select * from chau
/*======================================================*/
INSERT INTO
    temp  (ID, Name, isDelete )
SELECT
    ID, NAme, isdelete 
FROM
    chau
WHERE
    NOT EXISTS(
        SELECT 
            *
        FROM
            temp
        WHERE
            temp .id =chau.id AND
            temp .name =chau.name  And 
            temp.isDelete =chau.isdelete 
    )
      
    SELECT * FROM CHAU
    SELECT * FROM TEMP
    
    